﻿using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Exhibition.Dao;

using Exhibition.Service;

using Exhibition.Common.Helper;

using Exhibition.Dao.ViewModel;

namespace Exhibition.manager
{

    public partial class ProductClassDetail : BaseAdminPage
    {

        ProductClassModel model = new ProductClassModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                BindDrop();
                GetProductClass();
            }

        }

        private void BindDrop()
        {
            
            new ProductClassTree().DropDownTree.Bind(drpParent,"","0");
            drpParent.Items.Insert(0,new ListItem("作为一级栏目","0"));
            
        }

        private void GetProductClass()
        {

            model = CenterService.productClassService.GetOneById(reqID);
            if (model != null)
            {

                //栏目名称
                txtClassName.Value = model.ClassName;

                //排序
                txtOrderID.Value = model.OrderID.ToString();

                //上级
                
                 

            }

        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new ProductClassModel() : CenterService.productClassService.GetOneById(Convert.ToInt32(hfId.Value));
            //栏目名称
            model.ClassName = txtClassName.Value;

            //排序
            model.OrderID = Convert.ToInt32(txtOrderID.Value);

            //上级
            model.PreID = Convert.ToInt32(drpParent.SelectedValue );

            //
            model.SiteID = CurrentSite.Id;

            //
            model.CreateUserId = AdminUser.Id;

            if (CenterService.productClassService.Save(model) > 0)
            {

                JsHelper.Unblock(this, CommFunMsg.GetMessage("A0001", Lan.zh));
            }
            else {
                JsHelper.Alert(this,CommFunMsg.GetMessage("E0001",Lan.zh));
            }

        }

    }

}

